'''
基础层：封装元素定位和操作
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

class BasePage():
    def __init__(self,driver):
        self.driver =driver
    #打开网址
    def get_url(self,url):
        '''实现打开url界面'''
        self.driver.get(url)
    #定位元素
    def find_ele(self,loc):
        ele = self.driver.find_element(*loc)
        return ele
    #输入操作
    def input_ele(self,loc,value):
        ele = self.find_ele(loc)
        ele.send_keys(value)
    #点击操作
    def click_ele(self,loc):
        ele = self.find_ele(loc)
        ele.click()
    #清空输入框操作
    def ele_clear(self,loc):
        ele = self.find_ele(loc)
        ele.clear()
    #最大化窗口
    def ele_max(self):
        self.driver.maximize_window()
#测试一下
if __name__ == '__main__':
    url=r'https://www.baidu.com'
    kw_loc=(By.ID,'kw')
    su_loc =(By.ID,'su')

    value='selenium'

    chrome_location = r'E:\nmon\light_Chrome\chrome-win\chrome.exe'
    options = webdriver.ChromeOptions()
    options.binary_location = chrome_location

    driver = webdriver.Chrome(options=options)

    base_page=BasePage(driver)
    base_page.get_url(url)
    base_page.ele_max()
    base_page.ele_clear(kw_loc)
    base_page.input_ele(kw_loc,value)
    base_page.click_ele(su_loc)
    sleep(3)

    driver.quit()


